import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:openim_common/openim_common.dart';

import 'publish_logic.dart';

class PublishPage extends StatelessWidget {
  final logic = Get.find<PublishLogic>();
  
  PublishPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Styles.c_F8F9FA,
      appBar: AppBar(
        backgroundColor: Styles.c_FFFFFF,
        elevation: 0,
        title: Text(
          '发表',
          style: Styles.ts_0C1C33_17sp_medium,
        ),
        centerTitle: true,
        leading: IconButton(
          icon: Icon(Icons.close, color: Styles.c_0C1C33),
          onPressed: () => Get.back(),
        ),
        actions: [
          TextButton.icon(
            onPressed: logic.publish,
           
            label: Text(
              '发布',
              style: TextStyle(
                color:  Color(0xFFFFD54F), 
                fontSize: 16.sp,
                fontWeight: FontWeight.w500,
              ),
            ),
             icon: Icon(
              Icons.send,
              color: Color(0xFFFFD54F), 
              size: 16.w,
            ),
          ),
        ],
      ),
      body: Column(
        children: [
          // 用户信息和输入区域
          Container(
            color: Styles.c_FFFFFF,
            padding: EdgeInsets.all(16.w),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                // 用户头像
                CircleAvatar(
                  radius: 20.r,
                  backgroundImage: AssetImage('assets/images/avatar_placeholder.png'),
                ),
                12.horizontalSpace,
                // 输入区域
                Expanded(
                  child: TextField(
                    controller: logic.contentController,
                    maxLines: 6,
                    decoration: InputDecoration(
                      hintText: '想说点什么...',
                      hintStyle: TextStyle(
                        color: Styles.c_8E9AB0,
                        fontSize: 16.sp,
                      ),
                      border: InputBorder.none,
                    ),
                    style: TextStyle(
                      color: Styles.c_0C1C33,
                      fontSize: 16.sp,
                    ),
                  ),
                ),
              ],
            ),
          ),
          
          // 分隔线
          Container(
            height: 8.h,
            color: Styles.c_F8F9FA,
          ),
          
          // 功能选项列表
          Container(
            color: Styles.c_FFFFFF,
            child: Column(
              children: [
                _buildOptionItem(
                  icon: Icons.link,
                  title: '附加链接',
                  onTap: () {
                    // 附加链接功能
                  },
                ),
                _buildDivider(),
                _buildOptionItem(
                  icon: Icons.location_on,
                  title: '所在位置',
                  subtitle: logic.location.value.isEmpty ? null : logic.location.value,
                  onTap: logic.selectLocation,
                ),
                _buildDivider(),
                _buildOptionItem(
                  icon: Icons.people,
                  title: '谁可以看',
                  subtitle: logic.visibility.value,
                  onTap: logic.setVisibility,
                ),
                _buildDivider(),
                _buildOptionItem(
                  icon: Icons.alternate_email,
                  title: '提醒谁看',
                  onTap: () {
                    // 现联进者功能
                  },
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
  
  Widget _buildOptionItem({
    required IconData icon,
    required String title,
    String? subtitle,
    required VoidCallback onTap,
  }) {
    return InkWell(
      onTap: onTap,
      child: Padding(
        padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.h),
        child: Row(
          children: [
            Icon(
              icon,
              color: Styles.c_8E9AB0,
              size: 20.w,
            ),
            12.horizontalSpace,
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    title,
                    style: TextStyle(
                      color: Styles.c_0C1C33,
                      fontSize: 16.sp,
                    ),
                  ),
                  if (subtitle != null) ...[
                    4.verticalSpace,
                    Text(
                      subtitle,
                      style: TextStyle(
                        color: Styles.c_8E9AB0,
                        fontSize: 14.sp,
                      ),
                    ),
                  ],
                ],
              ),
            ),
            Icon(
              Icons.chevron_right,
              color: Styles.c_8E9AB0,
              size: 20.w,
            ),
          ],
        ),
      ),
    );
  }
  
  Widget _buildDivider() {
    return Container(
      height: 1.h,
      margin: EdgeInsets.only(left: 48.w),
      color: Styles.c_F0F2F6,
    );
  }
}